package exam.history.huawei03;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int size = Integer.parseInt(in.nextLine());
        int[][] nodes = new int[size][];
        for (int i = 0; i < size; i++) {
            nodes[i] = parseOneLine(in.nextLine());
        }
        int[] xy = parseOneLine(in.nextLine());
        String result = doQuery(nodes, xy[0], xy[1]);
        System.out.println(result);
    }

    private static int[] parseOneLine(String text) {
        ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
        Scanner in = new Scanner(stream);
        List<Integer> list = new ArrayList<>();
        while (in.hasNext()) {
            list.add(in.nextInt());
        }
        return list.stream().mapToInt(it -> it).toArray();
    }

    /**
     * 层序遍历
     */
    private static String doQuery(int[][] nodes, int x, int y) {
        List<int[]> curLayer = new ArrayList<>();
        curLayer.add(nodes[0]);
        return "{" + findAim(nodes, curLayer, 0, x, y) + "}";
    }

    private static String findAim(int[][] nodes, List<int[]> curLayer, int curDepth, int aimX, int aimY) {
        if (curDepth >= aimX) {
            if (curLayer.size() <= aimY) {
                return "";
            }
            try {
                // 我看不懂
                return "" + curLayer.get(aimY)[0];
            } catch (Throwable t) {
                // log
                return "";
            }
        }
        List<int[]> nextLayer = new ArrayList<>();
        for (int i = 0; i < curLayer.size(); i++) {
            // 注意它不是二叉树
            int[] curNode = curLayer.get(i);
            for (int j = 1; j < curNode.length; j++) {
                nextLayer.add(nodes[curNode[j]]);
            }
        }
        return findAim(nodes, nextLayer, curDepth + 1, aimX, aimY);
    }

}
